/* eslint-disable */
// @ts-ignore
import { queryOptions, useMutation } from '@tanstack/vue-query';
import type { DefaultError } from '@tanstack/vue-query';
import request from '@/utils/request';
import { CustomRequestOptions } from '@/interceptors/request';

import * as apis from './coreTarget';
import * as API from './types';

/** 分页查询核心指标 GET /core_target */
export function coreTargetGetCoreTargetPageQueryOptions(options: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.CoreTargetGetCoreTargetPageParams;
  options?: CustomRequestOptions;
}) {
  return queryOptions({
    queryFn: async ({ queryKey }) => {
      return apis.coreTargetGetCoreTargetPage(queryKey[1] as typeof options);
    },
    queryKey: ['coreTargetGetCoreTargetPage', options],
  });
}

/** 编辑核心指标 PUT /core_target */
export function useCoreTargetEditCoreTargetMutation(options?: {
  onSuccess?: (value?: API.ResponseModelObject_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.coreTargetEditCoreTarget,
    onSuccess(data: API.ResponseModelObject_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 新增核心指标 POST /core_target */
export function useCoreTargetAddCoreTargetMutation(options?: {
  onSuccess?: (value?: API.ResponseModelObject_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.coreTargetAddCoreTarget,
    onSuccess(data: API.ResponseModelObject_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 删除核心指标 DELETE /core_target */
export function useCoreTargetDeleteCoreTargetMutation(options?: {
  onSuccess?: (value?: API.ResponseModelObject_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.coreTargetDeleteCoreTarget,
    onSuccess(data: API.ResponseModelObject_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 查询核心指标列表 GET /core_target/list */
export function coreTargetGetCoreTargetListQueryOptions(options: {
  options?: CustomRequestOptions;
}) {
  return queryOptions({
    queryFn: async ({ queryKey }) => {
      return apis.coreTargetGetCoreTargetList(queryKey[1] as typeof options);
    },
    queryKey: ['coreTargetGetCoreTargetList', options],
  });
}
